//
//  ZH_FeaturesSelectCollectionViewCell.m
//  HenticaSample
//
//  Created by zhangliwen on 2018/5/2.
//  Copyright © 2018年 HenticaSample. All rights reserved.
//

#import "GC_FeaturesSelectCollectionViewCell.h"
@interface GC_FeaturesSelectCollectionViewCell()

///标题
@property (nonatomic, weak) UILabel *titleLabel;
@end
@implementation GC_FeaturesSelectCollectionViewCell
///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[GC_FeaturesSelectCollectionViewCell class] forCellWithReuseIdentifier:@"GC_FeaturesSelectCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"GC_FeaturesSelectCollectionViewCell" forIndexPath:indexPath];
}
//初始化
-(void)initDefault
{
    
}

///加载子视图约束
-(void)loadSubviewConstraints
{
    [self.pngImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView).offset(FITSCALE(17));
        make.top.equalTo(self.contentView);
        make.width.mas_equalTo(FITSCALE(62));
        make.height.mas_equalTo(FITSCALE(62));
        make.centerX.equalTo(self.contentView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.pngImageView.mas_bottom).offset(FITSCALE(7));
    }];
}


///更新ui
- (void)updateUiForData
{
    [self.pngImageView setImageForName:@"优选00"];
    self.titleLabel.text = @"优选";
}

///更新ui
- (void)updateUiWithImage:(NSString *)image andTitle:(NSString *)title
{
    [self.pngImageView setImageForName:image];
    self.titleLabel.text = title;
}
- (void)updateUiForDatas:(NSMutableDictionary *)data{
    if (data) {
        [self.pngImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"cate_img"]]] placeholderImage:nil];
        self.titleLabel.text = data[@"cate_name"];
    }
}

///更新 Ui
//- (void)updateuiForData:(GC_UserMenuInfoModel *)data
//{
//    if(data){
//        [self.pngImageView sd_setImageWithUrlString:[DATAMODEL pngBaseUrlWithPngUrl:data.pictureUrl] defaultImageName:Default_Pic];
//        self.titleLabel.text = data.name;
//    }
//}

#pragma mark -- getter,setter
///图片
- (UIImageView *)pngImageView
{
    if(!_pngImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius = FITSCALE(3);
        image.layer.masksToBounds = YES;
        image.contentMode = UIViewContentModeScaleAspectFill;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_pngImageView = image];
    }
    return _pngImageView;
}


///标题
- (UILabel *)titleLabel
{
    if(!_titleLabel){
        UILabel *label = [UILabel createLabelWithText:@"" font:kFontSize_26];
        [label setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
@end
